package com.demarc.pesquisas.infraestrutura.persistencia;

import javax.sql.DataSource;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;

public class SchemaCreator implements InitializingBean {

    private String systemSchema;
    private String externalSchema;
    private DataSource dataSource;

    @Override
    public void afterPropertiesSet() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        jdbcTemplate.execute("CREATE SCHEMA " + systemSchema + " AUTHORIZATION DBA");
        jdbcTemplate.execute("CREATE SCHEMA " + externalSchema + " AUTHORIZATION DBA");
    }

    public String getSystemSchema() {
        return systemSchema;
    }

    public void setSystemSchema(String systemSchema) {
        this.systemSchema = systemSchema;
    }

    public String getExternalSchema() {
        return externalSchema;
    }

    public void setExternalSchema(String externalSchema) {
        this.externalSchema = externalSchema;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
}